{include file='_header'}
<script type="text/javascript" src="__STATIC__/js/lib/moment.js"></script>
<link rel="stylesheet" href="__STATIC__/components/datetimepicker/jquery.datetimepicker.css">
<link rel="stylesheet" href="__STATIC__/components/daterangepicker/daterangepicker.css">
<style type='text/css'>
    .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th{
        padding: 10px 20px;
    }
    .table > tbody>.trbody > td{
        border-top:none !important;
    }
    .trhead td {  background:#efefef;text-align: center}
    .trbody td {  text-align: center; vertical-align:top;border-left:1px solid #f2f2f2;overflow: hidden; font-size:12px;}
    .trorder { background:#f8f8f8;border:1px solid #f2f2f2;text-align:left;}
    .ops { border-right:1px solid #f2f2f2; text-align: center;}
    .goodsRefund{
        border-bottom: 1px solid #efefef;
        flex-direction: initial;
        margin: 0 !important;
    }
</style>

<div class="page-header">
    当前位置：<span class="text-ptimary">订单管理</span>
    <span>(订单数:  <span class='text-danger'>{$total}</span> 订单金额:  <span class='text-danger'>{$totalmoney}</span> {if !empty($magent['nickname'])}订单推广人:  <span class='text-danger'>{$magent['nickname']}</span>{/if})</span>
</div>
<div class="page-content">
    <form action="" method="get" class="form-horizontal table-search" role="form">
        <input type="hidden" name="status" value="{$status}" />
        <input type="hidden" name="agentid" value="{$_GPC['agentid']}" />
        <input type="hidden" name="refund" value="{$_GPC['refund']}" />
        <div class="page-toolbar m-b-sm m-t-sm">
            <div class="col-sm-12">
                <div class="input-group">
                    <div class="input-group-select">
                        <select name="paytype" class="form-control" >
                            <option value="" {if $paytype==''}selected{/if}>支付方式</option>
                            {foreach name="paytype" key="key" item="type"}
                            <option value="{$key}" {if $paytype == "$key"} selected="selected" {/if}>{$type['name']}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="input-group-select">
                        <select name='searchtime'  class='form-control'>
                            <option value=''>不按时间</option>
                            <option value='create' {if $searchtime=='create'}selected{/if}>下单时间</option>
                            <option value='pay' {if $searchtime=='pay'}selected{/if}>付款时间</option>
                            <option value='send' {if $searchtime=='send'}selected{/if}>发货时间</option>
                            <option value='finish' {if $searchtime=='finish'}selected{/if}>完成时间</option>
                        </select>
                    </div>
                    <span class="input-group-btn">
                        {:tpl_form_field_daterange('time', array('starttime'=>date('Y-m-d H:i', $starttime),'endtime'=>date('Y-m-d H:i', $endtime)),true);}
                    </span>
                    <div class="input-group-select">
                        <select name='searchfield'  class='form-control'   style="width:95px;padding:0 5px;"  >
                            <option value='ordersn' {if $searchfield=='ordersn'}selected{/if}>订单号</option>
                            <option value='member' {if $searchfield=='member'}selected{/if}>会员信息</option>
                            <option value='address' {if $searchfield=='address'}selected{/if}>收件人信息</option>
                            <option value='location' {if $searchfield=='location'}selected{/if}>地址信息</option>
                            <option value='expresssn' {if $searchfield=='expresssn'}selected{/if}>快递单号</option>
                            <option value='goodstitle' {if $searchfield=='goodstitle'}selected{/if}>商品名称</option>
                            <option value='goodssn' {if $searchfield=='goodssn'}selected{/if}>商品编码</option>
                            <option value='saler' {if $searchfield=='saler'}selected{/if}>核销员</option>
                            <option value='store' {if $searchfield=='store'}selected{/if}>核销门店</option>
                        </select>
                    </div>
                    <input type="text" class="form-control"  name="keyword" value="{$keyword}" placeholder="请输入关键词"/>
                    <span class="input-group-btn">
                        <button class="btn btn-primary" type="submit"> 搜索</button>
                        <button type="submit" name="export" value="1" class="btn btn-success">导出</button>
                    </span>
                </div>
            </div>
        </div>
    </form>
    {if count($list)>0}
    <table class='table table-responsive' style='table-layout: fixed;'>
        <tr style='background:#f8f8f8'>
            <td style='width:60px;border-left:1px solid #f2f2f2;'>商品</td>
            <td style='width:150px;'></td>
            <td style='width:70px;text-align: right;;'>单价/数量</td>
            <td  style='width:100px;text-align: center;'>买家</td>
            <td style='width:90px;text-align: center;'>支付/配送</td>
            <td style='width:100px;text-align: center;'>价格</td>
            <td style='width:100px;text-align: center;'>操作</td>
            <td style='width:90px;text-align: center'>状态</td>
        </tr>
        {foreach name="list" item="item"}
        <tr ><td colspan='8' style='height:20px;padding:0;border-top:none;'>&nbsp;</td></tr>
        <tr class='trorder'>
            <td colspan='4' >
               <span style="font-weight: bold;">{:date('Y-m-d',$item['createtime'])} {:date('H:i:s',$item['createtime'])}</span>
                订单编号:  {$item['ordersn']}
                {if !empty($item['refundstate']) && $item['refundstate'] !=3}<label class='label label-danger'>{$r_type[$item['rtype']]}申请</label>{/if}
                {if !empty($item['refundstate']) && $item['refundstate'] !=3 && $item['rstatus'] == 4}<label class='label label-default'>客户退回物品</label>{/if}
                {if !empty($item['isluckbuy'])}<label class='label label-default'>幸运购订单</label>{/if}
            </td>
            <td colspan='4' style='text-align:right;font-size:12px;' class='aops'>
                {if $item['statusvalue'] == 2 && !empty($item['addressid'])}
                <a class="op" data-toggle="ajaxModal"  href="{:url('merch/order/changeexpress', array('id' => $item['id']))}">
                    <i class="icow icow-wuliu" title="修改物流" style="color: #999;display: inline-block;vertical-align: middle"></i>
                    修改物流
                </a>
                {/if}
                <a class='op'  data-toggle="ajaxModal" href="{:url('merch/order/remarksaler', array('id' => $item['id']))}">
                    <i class="icow icow-flag-o" style="color: #df5254;display: inline-block;vertical-align: middle" title="  查看备注"></i>备注 &nbsp;
                </a>
                {if empty($item['statusvalue'])}
                    {if $merch_user['changepricechecked'] == 1}
                    <a class='op'  data-toggle='ajaxModal' href="{:url('merch/order/changeprice',array('id'=>$item['id']))}">
                        <i class="icow icow-gaijia" title="订单改价"  style="color: #999;display: inline-block;vertical-align: middle"></i>
                        订单改价
                    </a>
                    {/if}
                    {if $item['parentid'] == 0}
                    <a class='op'  data-toggle='ajaxModal' href="{:url('merch/order/close',array('id'=>$item['id']))}" >
                        <i class="icow icow-shutDown" title="关闭订单"  style="color: #999;margin-right: 3px;display: inline-block;vertical-align: middle"></i>
                        关闭订单
                    </a>
                    {/if}
                {/if}
            </td>
        </tr>
        <?php $display_none=0;?>
        {foreach name="item['goods']" key="k" item="g"}
        <tr class='trbody {if $g['single_refundstate']>0}goodsRefund{/if}'>
            <td style='overflow:hidden;'><img src="{:tomedia($g['thumb'])}" style='width:50px;height:50px;border:1px solid #ccc; padding:1px;'></td>
            <td style='text-align: left;overflow:hidden;border-left:none;'  >{$g['title']}{if !empty($g['optiontitle'])}<br/>{$g['optiontitle']}{/if}<br/>{$g['goodssn']}</td>
            <td style='text-align:right;border-left:none;'>
                {:number_format($g['realprice']/$g['total'],2)}<br/>
                x{$g['total']}<br/>
                {if $g['single_refundstate']==8}
                <span class="text-danger">已拒绝</span>
                {elseif $g['single_refundstate']==9}
                    <span class="text-danger">维权成功</span>
                {elseif $g['single_refundstate']==1}
                    <span class="text-danger">退款中</span>
                {elseif $g['single_refundstate']==2}
                    <span class="text-danger">退货中</span>
                {/if}
            </td>
            {if $k==0}
                <td rowspan="{:count($item['goods'])}"  style='text-align: center;' >
                    <a href="{:url('merch/member/list/detail',array('id'=>$item['mid']))}"> {$item['nickname']}</a>
                    <br/>
                    {$item['addressdata']['realname']}<br/>{$item['addressdata']['mobile']}
                </td>
                <td rowspan="{:count($item['goods'])}" style='text-align:center;' >
                    <!-- 已支付 -->
                    {if $item['statusvalue'] > 0}
                    {if $item['paytypevalue']==1}
                    <span> <i class="icow icow-yue text-warning" style="font-size: 17px;"></i><span>余额支付</span></span>
                    {elseif $item['paytypevalue']==11}
                    <span> <i class="icow icow-kuajingzhifuiconfukuan text-danger" style="font-size: 17px"></i>后台付款</span>
                    {elseif $item['paytypevalue']==21}
                    <span> <i class="icow icow-weixinzhifu text-success" style="font-size: 17px"></i>微信支付</span>
                    {elseif $item['paytypevalue']==22}
                    <span><i class="icow icow-zhifubaozhifu text-primary" style="font-size: 17px"></i>支付宝支付</span>
                    {/if}
                    {elseif $item['statusvalue'] == 0}
                    <!-- 未支付 -->
                    {if $item['paytypevalue']!=3}
                    <span> <i class="icow icow-shibai text-danger" style="font-size: 17px"></i>未支付</span>
                    {else}
                    <span> <i class="text-primary icow icow-icon" style="font-size: 17px"></i>货到付款</span>
                    {/if}
                    {elseif $item['statusvalue'] == -1}
                    {if $item['paytypevalue']==1}
                    <span> <i class="icow icow-yue text-warning" style="font-size: 17px;display:inline-block;height: 17px;width: 17px;padding-top: 3px"></i><span>余额支付</span></span>
                    {elseif $item['paytypevalue']==11}
                    <span> <i class="icow icow-kuajingzhifuiconfukuan text-danger" style="font-size: 17px"></i>后台付款</span>
                    {elseif $item['paytypevalue']==21}
                    <span> <i class="icow icow-weixin text-success" style="font-size: 17px"></i>微信支付</span>
                    {elseif $item['paytypevalue']==22}
                    <span><i class="icow icow-zhifubao text-primary" style="font-size: 17px"></i>支付宝支付</span>
                    {/if}
                    {/if}
                    {if $item['paytypevalue'] == 3 && $item['is_cashier'] == 1}
                    <span style='margin-top:5px;display:block;'>收银台现金收款</span>
                    {else}
                    <span style='margin-top:5px;display:block;'>{$item['dispatchname']}</span>
                    {/if}
                </td>
                <td  rowspan="{:count($item['goods'])}" style='text-align:center' >
                ￥{:number_format($item['price'],2)} <a data-toggle='popover' data-html='true' data-placement='right' data-trigger="hover" data-content="<table style='width:100%;'>
                    <tr>
                        <td  style='border:none;text-align:right;'>商品小计：</td>
                        <td  style='border:none;text-align:right;;'>￥{:number_format( $item['goodsprice'] ,2)}</td>
                    </tr>
                    <tr>
                        <td  style='border:none;text-align:right;'>运费：</td>
                        <td  style='border:none;text-align:right;;'>￥{:number_format( $item['olddispatchprice'],2)}</td>
                    </tr>
                    {if $item['discountprice']>0}
                    <tr>
                        <td  style='border:none;text-align:right;'>会员折扣：</td>
                        <td  style='border:none;text-align:right;;'>-￥{:number_format( $item['discountprice'],2)}</td>
                    </tr>
                    {/if}
                    {if $item['deductprice']>0}
                    <tr>
                        <td  style='border:none;text-align:right;'>积分抵扣：</td>
                        <td  style='border:none;text-align:right;;'>-￥{:number_format( $item['deductprice'],2)}</td>
                    </tr>
                    {/if}
                    {if $item['deductcredit2']>0}
                    <tr>
                        <td  style='border:none;text-align:right;'>余额抵扣：</td>
                        <td  style='border:none;text-align:right;;'>-￥{:number_format( $item['deductcredit2'],2)}</td>
                    </tr>
                    {/if}
                    {if $item['deductenough']>0}
                    <tr>
                        <td  style='border:none;text-align:right;'>商城满额立减：</td>
                        <td  style='border:none;text-align:right;;'>-￥{:number_format( $item['deductenough'],2)}</td>
                    </tr>
                    {/if}
                    {if $item['merchdeductenough']>0}
                    <tr>
                        <td  style='border:none;text-align:right;'>商户满额立减：</td>
                        <td  style='border:none;text-align:right;;'>-￥{:number_format( $item['merchdeductenough'],2)}</td>
                    </tr>
                    {/if}
                    {if $item['couponprice']>0}
                    <tr>
                        <td  style='border:none;text-align:right;'>优惠券优惠：</td>
                        <td  style='border:none;text-align:right;;'>-￥{:number_format( $item['couponprice'],2)}</td>
                    </tr>
                    {/if}
                    {if $item['isdiscountprice']>0}
                    <tr>
                        <td  style='border:none;text-align:right;'>促销优惠：</td>
                        <td  style='border:none;text-align:right;;'>-￥{:number_format( $item['isdiscountprice'],2)}</td>
                    </tr>
                    {/if}
                    {if intval($item['changeprice'])!=0}
                    <tr>
                        <td  style='border:none;text-align:right;'>卖家改价：</td>
                        <td  style='border:none;text-align:right;;'><span style='{if 0<$item['changeprice']}color:green{else}color:red{/if}'>{if 0<$item['changeprice']}+{else}-{/if}￥{:number_format(abs($item['changeprice']),2)}</span></td>
                    </tr>
                    {/if}
                    {if intval($item['changedispatchprice'])!=0}
                    <tr>
                        <td  style='border:none;text-align:right;'>卖家改运费：</td>
                        <td  style='border:none;text-align:right;;'><span style='{if 0<$item['changedispatchprice']}color:green{else}color:red{/if}'>{if 0<$item['changedispatchprice']}+{else}-{/if}￥{:abs($item['changedispatchprice'])}</span></td>
                    </tr>
                    {/if}
                    <tr>
                        <td style='border:none;text-align:right;'>应收款：</td>
                        <td  style=`'border:none;text-align:right;color:green;'>￥{:number_format($item['price'],2)}</td>
                    </tr>
                </table> "
                    ><i class='fa fa-question-circle'></i></a>
                {if $item['dispatchprice']>0}
                <br/>(含运费:￥{:number_format( $item['dispatchprice'],2)})
                {/if}
            </td>
            {/if}
            {if empty($display_none)}
                <td style='text-align:center' {if empty($g['single_refundid'])}rowspan="{:count($item['goods'])-$k}"{/if}>
                    {if !empty($g['single_refundstate'])}
                        <a class='op  text-primary' style="line-height: 30px;" href="{:url('merch/order/single_refund', array('id' => $g['ogid']))}" >维权{if $item['refundstate']!=9}处理{else}详情{/if}</a><br/>
                        <a class='op text-primary'  href="{:url('merch/order/detail', array('id' => $item['id']))}" >查看详情</a><br/>
                        {if $item['addressid']!=0 && $item['statusvalue']>=2}
                            <a class='op text-primary'  data-toggle="ajaxModal" href="{:url('merch/util/express', array('id' => $item['id'],'express'=>$item['express'],'expresssn'=>$item['expresssn']))}">物流信息</a>
                        {/if}
                    {else}
                        {if !empty($item['refundid'])}
                            <a class='op text-primary'  href="{:url('merch/order/refund', array('id' => $item['id']))}" >维权{if $item['refundstate']>0}处理{else}详情{/if}</a><br/>
                        {/if}
                        <a class='op text-primary'  href="{:url('merch/order/detail', array('id' => $item['id']))}" >查看详情</a><br/>
                        {if $item['addressid']!=0 && $item['statusvalue']>=2}
                            <a class='op text-primary'  data-toggle="ajaxModal" href="{:url('merch/util/express', array('id' => $item['id'],'express'=>$item['express'],'expresssn'=>$item['expresssn']))}">物流信息</a>
                        {/if}
                        <?php $display_none=1;?>
                    {/if}
                </td>
            {/if}
            {if $k==0}                
                <td rowspan="{:count($item['goods'])}" class='ops' style='line-height:20px;text-align:center' ><span class="text-{$item['statuscss']}">{$item['status']}</span><br />{if $item['isluckbuy'] == 1 && (empty($item['lotterylog']) || $lotterylog['lotterylog']['is_reward'] != -1)} {else}{include file='order/ops'}{/if}
                </td>
            {/if}
        </tr>
        {/foreach}
        {if !empty($item['remark'])}
        <tr ><td colspan='8' style='background:#fdeeee;color:red;'>买家备注: {$item['remark']}</td></tr>
        {/if}
        {if !empty($level)}
            <tr style=";border-bottom:none;background:#f9f9f9;">
                <td colspan='4' style='text-align:left'>
                    {if !empty($agentid)}
                    <b>分销订单级别:</b> {$item['level']}级 <b>分销佣金:</b> {$item['commission']} 元
                    {/if}
                </td>
                <td colspan='4' style='text-align:right'>
                    {if empty($agentid)}
                    {if $item['commission1']!=-1}<b>1级佣金:</b> {$item['commission1']} 元 {/if}
                    {if $item['commission2']!=-1}<b>2级佣金:</b> {$item['commission2']} 元 {/if}
                    {if $item['commission3']!=-1}<b>3级佣金:</b> {$item['commission3']} 元 {/if}
                    {/if}
                </td>
            </tr>
        {else}
            <tr style=";border-bottom:none;background:#f9f9f9;">
                <td colspan='8' style='text-align:left'>
                </td>
            </tr>
        {/if}
        {/foreach}
        <tfoot>
            <tr>
                <td colspan="8" class="text-right">
                    {$pager}
                </td>
            </tr>
        </tfoot>
    </table>
    {else}
    <div class='panel panel-default'>
        <div class='panel-body' style='text-align: center;padding:30px;'>
            暂时没有任何订单!
        </div>
    </div>
    {/if}
</div>
{include file='_footer'}
